package com.zhenxiang.juc.list.unsafe;

import java.lang.reflect.Array;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author : James
 * @Create : 2021-12-21-16:28
 * @Description : 集合不安全
 */
public class ListTest {

    public static void main(String[] args) {

        //  线程不安全
       // List<String> list = new ArrayList<>();

        // 线程安全
        // Collection<String> list = Collections.synchronizedList(new ArrayList<>());

        // 读写分离 安全
         List<String> list = new CopyOnWriteArrayList<>();

        for (int i = 0; i < 10; i++) {

            new Thread(()->{
                list.add(UUID.randomUUID().toString().substring(0,5));
                System.out.println(list);
            },String.valueOf(i)).start();
        }
    }


}
